package com.ddwl.goods.controller;


import com.ddwl.common.annotation.Auth;
import com.ddwl.common.annotation.Submit;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.goods.service.LimitTimePurActiveService;
import com.ddwl.schema.bo.goods.LimitTimePurActiveBo;
import com.ddwl.schema.bo.goods.QueryLimitTimePurActiveBo;
import com.ddwl.schema.bo.goods.QueryLimitTimePurGoodBo;
import com.ddwl.schema.bo.goods.UpdateLimitTimePurActiveBo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.goods.LimitTimeGoAndTimeVo;
import com.ddwl.schema.vo.goods.LimitTimePurActiveVo;
import com.ddwl.schema.vo.goods.LimitTimePurGoodVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 创建限时活动
 * @author wenbin
 */
@Api(tags = "限时活动")
@Slf4j
@RequestMapping("/limitTimePurActive")
@RestController
public class LimitTimePurActiveController extends BaseController {

    @Resource
    private LimitTimePurActiveService limitTimePurActiveService;

    @Submit
    @PostMapping("/create")
    @Auth(product={BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    @ApiOperation("创建限时抢购活动")
    public RestVo create(@Valid @RequestBody LimitTimePurActiveBo bo) {
        limitTimePurActiveService.create(bo,getUserId());
        return RestVo.ok();
    }

    @PostMapping("/update")
    @Auth(product={BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    @ApiOperation("修改限时购")
    public RestVo update(@Valid @RequestBody UpdateLimitTimePurActiveBo bo) {
        limitTimePurActiveService.update(bo,getUserId());
        return RestVo.ok();
    }

    @PostMapping("/deleteLimitGood")
    @Auth(product={BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    @ApiOperation("删除限时购商品")
    public RestVo deleteLimitGood(@Valid @RequestBody UpdateLimitTimePurActiveBo bo) {
        limitTimePurActiveService.deleteLimitGood(bo,getUserId());
        return RestVo.ok();
    }

    @DeleteMapping("/delete/{activeId}")
    @Auth(product={BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    @ApiOperation("删除限时购活动")
    public RestVo deleteSeckill(@PathVariable String activeId) {
        limitTimePurActiveService.delete(activeId);
        return RestVo.ok();
    }

    @PostMapping("/queryPageActive")
    @ApiOperation("首页查询限时购活动")
    public RestVo<LimitTimePurActiveVo> queryPageActive(@RequestBody QueryLimitTimePurActiveBo bo) {
        return RestVo.ok(limitTimePurActiveService.queryPageActive(bo));
    }

    @PostMapping("/queryActive")
    @ApiOperation("运营工具限时购活动")
    @Auth(product={BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo<List<LimitTimePurActiveVo>> queryActive(@RequestBody QueryLimitTimePurActiveBo bo) {
        //bo.setShopId(getShopId());
        return RestVo.ok(limitTimePurActiveService.queryActive(bo,getUserId()));
    }

    @PostMapping("/queryGoodDetail")
    @ApiOperation("运营工具限时购商品详情")
    @Auth(product={BaseEnum.ProductEnum.API})
    public RestVo<LimitTimePurGoodVo> queryGoodDetail(@RequestBody QueryLimitTimePurGoodBo bo) {
        return RestVo.ok(limitTimePurActiveService.getLimitItemDetail(bo));
    }


    @PostMapping("/querySeckillItemList")
    @Auth(product={BaseEnum.ProductEnum.API})
    @ApiOperation("查询秒杀商品列表(收藏夹用)")
    public RestVo<List<LimitTimePurGoodVo>> querySeckillItemList(@RequestBody QueryLimitTimePurGoodBo bo) {
        //return RestVo.ok(limitTimePurActiveService.getLimitItemDetail(bo));
        return null;
    }

    @GetMapping("/limitTimeGo")
    @ApiOperation("查询当前时间以及是否有限时购活动")
    public RestVo<LimitTimeGoAndTimeVo> limitTimeGo(@RequestParam String shopId){
        return RestVo.ok(limitTimePurActiveService.limitTimeGo(shopId));
    }


}
